package com.sti.platform.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aisino.core.common.JsonPost;
import com.aisino.core.controller.BaseController;
import com.sti.platform.model.Role;
import com.sti.platform.service.RoleService;

@Controller
@RequestMapping("role")
public class RoleCotroller extends BaseController {
	@Autowired
	private RoleService roleService;
	
	@RequestMapping("list")
	public String queryList(HttpServletRequest request,Integer index,Integer row){
		String params = request.getParameter("params");
		List<Role> list = roleService.queryRole(params,index, row);
		request.setAttribute("list", list);
		return "user/role";
	}
	
	@RequestMapping("add")
	public String addRole(){
		return "user/add_role";
	}
	
	@RequestMapping("editor")
	public String editorRole(HttpServletRequest request){
		String roleId = request.getParameter("roleId");
		request.setAttribute("role", roleService.queryRole(roleId));
		return "user/editor_role";
	}

	@RequestMapping("addRole")
	public @ResponseBody Map add(final Role role){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				roleService.addRole(role);
			}
		});
	}
	
	@RequestMapping("delect")
	public @ResponseBody Map  delect(final String roleId){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				roleService.delectRole(roleId);
			}
		});
	}
	
	@RequestMapping("delects")
	public @ResponseBody Map delectList(final String roleIds){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				roleService.delectRoles(roleIds);
			}
		});
	}
	
	@RequestMapping("updateRole")
	public @ResponseBody Map updateRole(final Role role){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				roleService.updateRole(role);
			}
		});
	}
	
	@RequestMapping("updateStatu")
	public @ResponseBody Map updateStatu(final String roleId,final Integer status){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				roleService.updateStatu(roleId, status);
			}
		});
	}
	
	@RequestMapping("updateStatus")
	public @ResponseBody Map updateStatus(final List<String> roleIds,final Integer status){
		return super.jsonPost(new JsonPost(){
			public void doInstancePost(Map map){
				roleService.updateStatus(roleIds, status);
			}
		});
	}
}
